const express = require('express');
const router = express.Router();
const AIClassificationController = require('../controllers/AIClassificationController');
const authenticate = require('../middleware/auth');

/**
 * @swagger
 * tags:
 *   name: AI Classification
 *   description: AI智能分类服务
 */

// All routes require authentication
router.use(authenticate);

/**
 * @swagger
 * /api/ai/bills/{billId}/suggest:
 *   post:
 *     summary: 为账单生成AI分类建议
 *     tags: [AI Classification]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: billId
 *         required: true
 *         schema:
 *           type: integer
 *         description: 账单ID
 *     responses:
 *       200:
 *         description: 成功生成AI分类建议
 *       401:
 *         description: 未授权
 *       404:
 *         description: 账单未找到
 *       500:
 *         description: 服务器内部错误
 */
router.post('/bills/:billId/suggest', AIClassificationController.generateSuggestion);

/**
 * @swagger
 * /api/ai/bills/{billId}/apply:
 *   post:
 *     summary: 应用AI分类建议到账单
 *     tags: [AI Classification]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: billId
 *         required: true
 *         schema:
 *           type: integer
 *         description: 账单ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - suggested_category
 *             properties:
 *               suggested_category:
 *                 type: string
 *                 description: 建议的分类名称
 *     responses:
 *       200:
 *         description: 成功应用AI分类建议
 *       400:
 *         description: 请求参数错误
 *       401:
 *         description: 未授权
 *       404:
 *         description: 账单未找到
 *       500:
 *         description: 服务器内部错误
 */
router.post('/bills/:billId/apply', AIClassificationController.applySuggestion);

/**
 * @swagger
 * /api/ai/bills/{billId}/suggestions:
 *   get:
 *     summary: 获取账单的AI分类建议历史
 *     tags: [AI Classification]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: billId
 *         required: true
 *         schema:
 *           type: integer
 *         description: 账单ID
 *     responses:
 *       200:
 *         description: 成功获取AI分类建议历史
 *       401:
 *         description: 未授权
 *       404:
 *         description: 账单未找到
 *       500:
 *         description: 服务器内部错误
 */
router.get('/bills/:billId/suggestions', AIClassificationController.getSuggestions);

module.exports = router;